{
 "metadata": {
  "name": "03-SimpleComponents"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Importar el pyoptools para poder realizar los calculos de trazo de rayos"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from pyoptools.all import *"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Creando componentes"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Crear una lente esferica"
     ]
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "1 - Crear las superficies con las que se van a crear la componente. "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "S0=Spherical(shape=Circular(radius=50),curvature=1./200.)\n",
      "S1=Spherical(shape=Circular(radius=50),curvature=1./200.)\n",
      "S2=Cylinder(radius=50,length=10)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "2- Armar la componente con las superficies creadas"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L1=Component(surflist=[(S0,(0,0,-5),(0,0,0)),\n",
      "                       (S1,(0,0,5),(0,0,0)),\n",
      "                       (S2,(0,0,6.5),(0,0,0))\n",
      "                       ],material=schott[\"BK7\"])\n",
      "plot3D(L1,size=(120,120),scale=3,rot=[(pi/3,0,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Crear un prisma de 90 grados"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "width=50\n",
      "height=50\n",
      "reflectivity=0.5\n",
      "        \n",
      "a_face= Plane(shape=Rectangular(size=(width,height)))\n",
      "b_face= Plane(shape=Rectangular(size=(width,height)))\n",
      "\n",
      "\n",
      "h=sqrt(2.)*width\n",
      "h_face= Plane (shape=Rectangular(size=(h,height)),reflectivity=reflectivity)\n",
      "        \n",
      "w2=width/2.\n",
      "\n",
      "e1=Plane (shape=Triangular(((-w2,w2),(-w2,-w2),(w2,-w2))))\n",
      "e2=Plane (shape=Triangular(((-w2,w2),(-w2,-w2),(w2,-w2))))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "P=Component(surflist=[(a_face,(0,0,-width/2),(0,0,0)),\n",
      "                      (b_face,(width/2,0,0),(0,pi/2,0)),\n",
      "                      (h_face,(0,0,0),(0,-pi/4,0)),\n",
      "                      (e1,(0,height/2,0),(pi/2,-pi/2,0)),\n",
      "                      (e2,(0,height/2,0),(pi/2,-pi/2,0))\n",
      "                      ],material=schott[\"BK7\"])\n",
      "plot3D(P,size=(120,120),scale=3,rot=[(pi/6,pi/8,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Crear un cubo divisor de haz"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def prisma(reflectivity=0):\n",
      "    width=50\n",
      "    height=50\n",
      "    a_face= Plane(shape=Rectangular(size=(width,height)))\n",
      "    b_face= Plane(shape=Rectangular(size=(width,height)))\n",
      "\n",
      "    h=sqrt(2.)*width\n",
      "    h_face= Plane (shape=Rectangular(size=(h,height)),reflectivity=reflectivity)\n",
      "        \n",
      "    w2=width/2.\n",
      "\n",
      "    e1=Plane (shape=Triangular(((-w2,w2),(-w2,-w2),(w2,-w2))))\n",
      "    e2=Plane (shape=Triangular(((-w2,w2),(-w2,-w2),(w2,-w2))))\n",
      "    P=Component(surflist=[(a_face,(0,0,-width/2),(0,0,0)),\n",
      "                      (b_face,(width/2,0,0),(0,pi/2,0)),\n",
      "                      (h_face,(0,0,0),(0,-pi/4,0)),\n",
      "                      (e1,(0,height/2,0),(pi/2,-pi/2,0)),\n",
      "                      (e2,(0,height/2,0),(pi/2,-pi/2,0))\n",
      "                      ],material=schott[\"BK7\"])\n",
      "    return P\n",
      "P1=prisma()\n",
      "P2=prisma(reflectivity=.5)\n",
      "\n",
      "cube=System(complist=[(P1,(0,0,0),(0,0,0)),(P2,(0,0,0),(0,pi,0))],n=1.)\n",
      "\n",
      "plot3D(cube,size=(120,120),scale=3,rot=[(pi/6,pi/8,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}